package org.iks.common.exception;

import lombok.extern.slf4j.Slf4j;
import org.iks.common.AjaxResult;
import org.iks.common.ResultCode;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @author kzou
 * @date 2023/11/18 11:19
 * @description: 异常统一处理器
 */
@Slf4j
@RestControllerAdvice
public class ExceptionProcessor {

    @ExceptionHandler(BusinessException.class)
    public AjaxResult<?> businessExceptionHandler(BusinessException e) {
        e.printStackTrace();
        return AjaxResult.error(e);
    }

    @ExceptionHandler(Exception.class)
    public AjaxResult<?> exceptionHandler(Exception e) {
        e.printStackTrace();
        log.error("cache a exception: {} {}", e.getMessage(), e.getStackTrace());
        return AjaxResult.error(ResultCode.ERROR);
    }


}
